if (GBrowserIsCompatible()) {
	function initializeMap(mapContainer, fnCallback, mapHtmlFile) {
		log("initializeMap was just called: ");
		function log(sVal, oValue, iLevel) {
			if (cN && cN.log) {
				cN.log(sVal, oValue, iLevel);
			} else {
				YAHOO.log(sVal + ": " + oValue);
			}
		}
		mapHtmlFile = (mapHtmlFile) ? mapHtmlFile : "js/map/map.html";
		/* everything to init the map should go here */
		YAHOO.util.Connect.asyncRequest("GET", mapHtmlFile, {success:function (o) {
			mapContainer.innerHTML = o.responseText;
			log("got the html template");
			var latTextArea = $("latitude");
			var lngTextArea = $("longitude");
			var lblTextArea = $("loc-label");
			var addTextArea = $("address-lookup-field");
			var metaMapTab = $("map-meta-map-tab");
			var searchButton = $("address-lookup-button");
			var saveButton = $("save-map-meta");
			var mapDiv = $("map");
		    
		    var oMenu = new YAHOO.widget.Menu("basicmenu",{ visible: true, width: "98%", position:"static"});
			oMenu.render(YAHOO.util.Dom.get("pointMenuContainer"));
			
			function getShowAddress(geocoder, addMarkOrPoint, addMenu,openInfo) {
				return function showAddress() {
					var address = addTextArea.value;
					YAHOO.log("About to look up: " + address);
					geocoder.getLatLng(address, function (point) {
						if (!point) {
							alert(address + " not found");
						} else {
							addMarkOrPoint(null, point);
							lblTextArea.value=address;
							addMenu();
							openInfo();
						}
					});
				};
			}
			function getAddMarkOrPointFn(map, marker) {
				var setDefault = setDefaults(marker);
				return function (nMarker, point) {
					if (!nMarker) {
						map.closeInfoWindow();
						marker.setPoint(point);
						map.panTo(point);
						setDefault();
					}
				};
			}
			function openInfoWindow(marker, tabs) {
				return function () {
					marker.openInfoWindowTabs(tabs, {maxWidth:300});
					if (getMarker(marker.getPoint())) {
						saveButton.value="Delete";
					} else {
						saveButton.value="Save";
					}
				};
			}
			function setDefaults(marker) {
				return function () {
					lblTextArea.value = "New Point";
					addTextArea.value = "";
					setFields(marker.getPoint());
				};
			}
			function roundPoint(num, X) {
				X = (!X ? 6 : X);
				return Math.round(num * Math.pow(10, X)) / Math.pow(10, X);
			}
			function setFields(gLatLng) {
				lngTextArea.value = roundPoint(gLatLng.lng());
				latTextArea.value = roundPoint(gLatLng.lat());
				log("Just set the lat lng text fields to: ", {lat:latTextArea.value, lng:lngTextArea.value});
			}
			function getMarker(point){
				var menuItems = oMenu.getItems();
				var mk;
				for (var i=0;i<menuItems.length;i++){
					var comp = (menuItems[i].data.pt==point);
					if (comp) {
						mk=menuItems[i];
					}
				}
				return mk;
			}
			function getNewMenuItem(marker,addMarkOrPoint,openInfo,map){
				return function(){
					/* first lets check the list to see if we already have this point */
					var mk=getMarker(marker.getPoint());
					if (!mk) {
						var menu = new YAHOO.widget.MenuItem(lblTextArea.value);
						menu.data = {lbl:lblTextArea.value,pt:marker.getPoint()};
						menu.clickEvent.subscribe(function(sEvt,oEvt){
							addMarkOrPoint(null,menu.data.pt);
							lblTextArea.value=menu.data.lbl;
							openInfo();
						});
					    oMenu.addItem(menu);
						oMenu.render();
					} else {
					    oMenu.removeItem(mk);						
						/* alert("You have already saved this point."); */
					}
					map.closeInfoWindow();
				};
			}
			/* this calls the method passed in with the init methon in it*/
			fnCallback(function () {
				log("instantiating the map");				
				var map = new GMap2(mapDiv);
				var startingCenter = new GLatLng(38.92255806063647, -77.23161220550537);
				var locTab = new GInfoWindowTab("Info", metaMapTab);
				var tabs = [locTab];
				var cp = new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(211, 20));
				var marker = new GMarker(startingCenter, {draggable:true});
				var openInfo = openInfoWindow(marker, tabs);
				var setDefault = setDefaults(marker);
				var addMarkOrPoint = getAddMarkOrPointFn(map, marker);
				var geocoder = new GClientGeocoder();
				
				
				
				var addMenuItem = getNewMenuItem(marker,addMarkOrPoint,openInfo,map);
				
				var showAddress = getShowAddress(geocoder, addMarkOrPoint,addMenuItem,openInfo);
				
				// map.addControl(new GSmallMapControl());
				map.addControl(new GOverviewMapControl()); 
				map.addControl(new GLargeMapControl()); 
				map.addControl(new GMapTypeControl(), cp);
				map.setCenter(startingCenter, 13);
				map.addOverlay(marker);

				YAHOO.util.Event.addListener(saveButton, "click",addMenuItem);				
				var kl = new YAHOO.util.KeyListener(lblTextArea, { keys:13 },addMenuItem); 
				kl.enable();
				
				YAHOO.util.Event.addListener(searchButton, "click",showAddress);
				var k2 = new YAHOO.util.KeyListener(addTextArea, { keys:13 },showAddress); 
				k2.enable();

				/* the marker is already set here but this call is here to init the other stuff*/
				addMarkOrPoint(null, startingCenter);
				
				GEvent.addListener(map, "click", addMarkOrPoint);
				GEvent.addListener(marker, "click", function () {
					log("marker click event");
					openInfo();
				});
				GEvent.addListener(marker, "dragend", function () {
					log("dragend event");
					/*setFields(marker.getPoint());*/
					addMarkOrPoint(null, marker.getPoint());
					/* setTimeout(openInfo,500); */
					/*map.panTo(marker.getPoint());*/
				});
				GEvent.addListener(marker, "dragstart", function () {
					log("dragstart event");
					setDefaults(marker);
					map.closeInfoWindow();
				});
				return map;
			});
		}, failure:function (o) {
			YAHOO.log("failed to get " + mapHtmlFile + ": " + o.status);
		}});
	}
}